gtk-demo: Improve flowbox demo code
authorBenjamin Otte <otte@redhat.com>
Fri, 3 Oct 2014 04:45:38 +0000 (06:45 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 3 Oct 2014 04:45:38 +0000 (06:45 +0200)
Overriding the background color for a color swatch is wrong. The color
is not the background, it's the foreground, so it should be painted in
a draw signal handler.

demos/gtk-demo/flowbox.c

index c0d921735d732cfaefb91d527e272bac6ac83f42..38ce3c06b0ffcfd90be02fa80f69063cf419cb8c 100644 (file)
 
 static GtkWidget *window = NULL;
 
+static gboolean
+draw_color (GtkWidget  *drawingarea,
+            cairo_t    *cr,
+            const char *color_name)
+{
+  GdkRGBA rgba;
+
+  if (gdk_rgba_parse (&rgba, color_name))
+    {
+      gdk_cairo_set_source_rgba (cr, &rgba);
+      cairo_paint (cr);
+    }
+
+  return FALSE;
+}
+
 static GtkWidget *
 color_swatch_new (const gchar *color)
 {
   GtkWidget *button, *area;
-  GdkRGBA rgba;
-
-  gdk_rgba_parse (&rgba, color);
 
   button = gtk_button_new ();
   area = gtk_drawing_area_new ();
+  g_signal_connect (area, "draw", G_CALLBACK (draw_color), (gpointer) color);
   gtk_widget_set_size_request (area, 24, 24);
-  gtk_widget_override_background_color (area, 0, &rgba);
   gtk_container_add (GTK_CONTAINER (button), area);
   gtk_widget_show_all (button);